//
//  NetworkImageView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/9.
//

import SwiftUI
import Kingfisher
import SDWebImageSwiftUI

struct AvatarImageView: View {
    let url: String
    let size : CGFloat
    @State private var isImageLoading = true
    
    var body: some View {
        ZStack {
            //图片
            if isImageLoading {
                Image(.appDefaultLogo)
                    .resizable()
                    .scaledToFill()
                    .padding(.horizontal, size / 4)
                    .padding(.vertical, size / 4)
                    .frame(width: size,height: size)
            }
            AnimatedImage(url: URL(string: url.formatCdn()))
                .resizable()
                .scaledToFill()
                .frame(width: size, height: size) // 设置你想要的尺寸
                .clipped() // 防止图片超出边界
                .aspectRatio(contentMode: .fill) // 保持图片的宽高比
                .clipShape(Circle())
        }
    }
}

#Preview {
    AvatarImageView(url: "",size: 50)
}
